home *** CD-ROM | disk | FTP | other *** search
- global gObjectsA, gObjectsB, gObjectsC, gObjectsD, gObjectsE, gObjectsF, gObjectsG, gObjectsH, gWorld, gStates, gOBJECTS, void, gFixPalette, miscXobj, gInitalized, noav, gNextEnvLetter, gNextDIRFile, gMIDIPlayTRUE, noteObjs, windowsMIDIXObj, xNAVXOBJ, xCURXOBJ, gCPU, gfileSep, gRootPath, gHDpath, gXobjs, gXOBJPath, gCDpath, gCDName, gInstrumentScale, sPALETTE, HARP, TIGO, HORN, DRUM, CHIME, BASS, wholeToneScale, harmonicMinorScale, majorScale, bluesScale, gScales, gMIDIINTERRUPTFREQUENCY, gMIDIINTERRUPTDURATION, gNotes, gMidiManager, gCDNotes, outDevNumsList, myMidiDevice, gLimitPreLoad
-
- on InitXOBJs
- if listp(gXobjs) then
- exit
- end if
- InitalizePaths()
- OpenChaosXlibs()
- if not noav then
- set xMIDI to OpenMIDIXOBJ()
- end if
- if gCPU = #MAC then
- set gFixPalette to FixPalette(mnew, the stageLeft, the stageTop, the stageRight, the stageBottom)
- end if
- set xNAVXOBJ to OffScreen(mnew, string(gCDName & "CODE" & gfileSep & "NAV.BMP"), 0, 0, 4)
- set gXobjs to [#MIDI: xMIDI, #NAV: xNAVXOBJ]
- end
-
- on CloseUniversalXOBJs
- if not noav then
- CLOSEMIDIXOBJ()
- end if
- if objectp(xNAVXOBJ) then
- xNAVXOBJ(mdispose)
- end if
- if objectp(xCURXOBJ) then
- xCURXOBJ(mdispose)
- end if
- if objectp(gFixPalette) then
- gFixPalette(mdispose)
- end if
- if objectp(miscXobj) then
- miscXobj(mdispose)
- end if
- openXLib(string(gXOBJPath & "MovieUtilities XObj"))
- CLOSEChaosXlibs()
- set gXobjs to void
- end
-
- on InitalizePaths
- if the machineType = 256 then
- set gfileSep to "\"
- if voidp(gHDpath) then
- set gHDpath to "C:\chaos\"
- end if
- if voidp(gCDpath) then
- set gCDpath to "D:\"
- end if
- set gCDName to gCDpath
- set gXOBJPath to gCDName & "XOBJs\"
- else
- set gCPU to #MAC
- set gfileSep to ":"
- set gHDpath to the pathName
- set gCDName to "Chaos:"
- set gXOBJPath to gCDName & "XOBJMAC:"
- end if
- end
-
- on OpenChaosXlibs
- if gCPU = #mpc then
- openXLib(string(gHDpath & "FILEIO.DLL"))
- openXLib(string(gXOBJPath & "MovUtils.DLL"))
- openXLib(string(gXOBJPath & "MISC_X.DLL"))
- openXLib(string(gXOBJPath & "OFFSCRN.DLL"))
- openXLib(string(gXOBJPath & "MIDIXOBJ.DLL"))
- else
- if gCPU = #MAC then
- openXLib(string(gXOBJPath & "FixPalette XObj"))
- openXLib(string(gXOBJPath & "MovieUtilities XObj"))
- openXLib(string(gXOBJPath & "Misc_X XObj"))
- openXLib(string(gXOBJPath & "OffScreenXOBJ"))
- if not noav then
- openXLib(string(gXOBJPath & "PlayNote.Xobj"))
- end if
- end if
- end if
- end
-
- on CLOSEChaosXlibs
- if gCPU = #mpc then
- closeXLib(string(gHDpath & "FILEIO.DLL"))
- closeXLib(string(gXOBJPath & "MovUtils.DLL"))
- closeXLib(string(gXOBJPath & "MISC_X.DLL"))
- closeXLib(string(gXOBJPath & "OFFSCRN.DLL"))
- closeXLib(string(gXOBJPath & "MIDIXOBJ.DLL"))
- else
- if gCPU = #MAC then
- closeXLib(string(gXOBJPath & "FixPalette XObj"))
- closeXLib(string(gXOBJPath & "MovieUtilities XObj"))
- closeXLib(string(gXOBJPath & "Misc_X XObj"))
- closeXLib(string(gXOBJPath & "OffScreenXOBJ"))
- if not noav then
- closeXLib(string(gXOBJPath & "PlayNote.Xobj"))
- end if
- end if
- end if
- end
-
- on writeWindowsMIDIProgramChange instrument, progNum
- set str to string(192 + instrument - 1 && progNum)
- windowsMIDIXObj(mWrite, str)
- end
-
- on closeMIDIXObjOut
- if gCPU = #mpc then
- if objectp(windowsMIDIXObj) then
- windowsMIDIXObj(mCloseOut)
- end if
- end if
- end
-
- on openMIDIXObjOut
- if gCPU = #mpc then
- if objectp(windowsMIDIXObj) then
- windowsMIDIXObj(mCloseOut)
- else
- abort()
- end if
- if count(outDevNumsList) > 0 then
- set outDevID to getAt(outDevNumsList, myMidiDevice)
- if windowsMIDIXObj(mOpenOut, outDevID, 1024) then
- beep()
- alert("The selected device appears to be busy by another application. Please quit all other applications and restart game.")
- abort()
- end if
- else
- abort()
- end if
- writeWindowsMIDIProgramChange(HARP, 8)
- writeWindowsMIDIProgramChange(TIGO, 14)
- writeWindowsMIDIProgramChange(HORN, 66)
- writeWindowsMIDIProgramChange(DRUM, 115)
- writeWindowsMIDIProgramChange(CHIME, 99)
- writeWindowsMIDIProgramChange(BASS, 37)
- end if
- end
-
- on OpenMIDIXOBJ
- initScalesMixxer()
- if gCPU = #mpc then
- if objectp(windowsMIDIXObj) then
- CLOSEMIDIXOBJ()
- end if
- set windowsMIDIXObj to midixobj(mnew)
- if not objectp(windowsMIDIXObj) then
- go("warning", "Intro")
- alert("Could not find Midi.dll")
- end if
- set devNumsList to value(windowsMIDIXObj(mGetDevIDs))
- set outDevNumsList to getAt(devNumsList, 2)
- if count(outDevNumsList) > 0 then
- if loadPrefData() then
- else
- set myMidiDevice to 1
- set gLimitPreLoad to 0
- end if
- set outDevID to getAt(outDevNumsList, myMidiDevice)
- if windowsMIDIXObj(mOpenOut, outDevID, 1024) then
- beep()
- go("warning", "Intro")
- alert("The selected device appears to be busy by another application. Please quit all other applications and restart game.")
- abort()
- end if
- else
- go("warning", "Intro")
- abort()
- end if
- writeWindowsMIDIProgramChange(HARP, 8)
- writeWindowsMIDIProgramChange(TIGO, 14)
- writeWindowsMIDIProgramChange(HORN, 66)
- writeWindowsMIDIProgramChange(DRUM, 115)
- writeWindowsMIDIProgramChange(CHIME, 99)
- writeWindowsMIDIProgramChange(BASS, 37)
- set midiObj to windowsMIDIXObj
- else
- if listp(noteObjs) then
- CLOSEMIDIXOBJ()
- end if
- set noteObjs to []
- add(noteObjs, playNote(mnew, 8, 2, 1, 0))
- add(noteObjs, playNote(mnew, 14, 2, 1, 0))
- add(noteObjs, playNote(mnew, 66, 2, 1, 0))
- add(noteObjs, playNote(mnew, 115, 2, 1, 0))
- add(noteObjs, playNote(mnew, 99, 2, 1, 0))
- add(noteObjs, playNote(mnew, 37, 2, 1, 0))
- set midiObj to noteObjs
- end if
- set gCDNotes to [#HARP: [], #Timur: [], #HORN: [], #DRUM: [], #CHIME: [], #BASS: []]
- InitMidiGlobals()
- return midiObj
- end
-
- on InitMidiGlobals
- set gNotes to [#HARP: [], #Timur: [], #HORN: [], #DRUM: [], #CHIME: [], #BASS: []]
- set gMidiManager to [#HARP: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 1, #Start: -1, #stop: 0], #Timur: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 2, #Start: -1, #stop: 0], #HORN: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 3, #Start: -1, #stop: 0], #DRUM: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 4, #Start: -1, #stop: 0], #CHIME: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 5, #Start: -1, #stop: 0], #BASS: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 6, #Start: -1, #stop: 0]]
- end
-
- on CLOSEMIDIXOBJ
- if gCPU = #mpc then
- if objectp(windowsMIDIXObj) then
- windowsMIDIXObj(mCloseOut)
- windowsMIDIXObj(mdispose)
- set windowsMIDIXObj to EMPTY
- end if
- else
- repeat with ix = 1 to 6
- set obj to getAt(noteObjs, ix)
- if objectp(obj) then
- set objectsExist to 1
- obj(mDisposePrep)
- obj(mdispose)
- end if
- setAt(noteObjs, ix, EMPTY)
- end repeat
- set noteObjs to EMPTY
- end if
- end
-
- on initScalesMixxer
- set HARP to 1
- set TIGO to 2
- set HORN to 3
- set DRUM to 4
- set CHIME to 5
- set BASS to 6
- set wholeToneScale to list(1, 3, 5, 7, 9, 11)
- set harmonicMinorScale to list(1, 3, 4, 6, 8, 9, 11)
- set majorScale to list(1, 3, 5, 6, 8, 10, 11)
- set bluesScale to list(1, 4, 6, 8, 10)
- set gScales to [wholeToneScale, harmonicMinorScale, majorScale, bluesScale]
- set gInstrumentScale to [1, 2, 3, 4, 1, 2]
- end
-
- on setPaletteAndScale instrumentNum, selection, obj
- set cnum to getaProp(getaProp(obj, #cast), string(selection))
- set spriteNum to getaProp(obj, #spriteNum)
- set the castNum of sprite spriteNum to cnum
- setaProp(obj, #DisplayState, string(selection))
- updateStage()
- setAt(gInstrumentScale, instrumentNum, selection)
- end
-
- on getRandomNote instrument, loOctave, hiOctave
- set scale to getAt(gScales, getAt(gInstrumentScale, instrument))
- set noteNum to getAt(scale, random(count(scale))) - 1
- set octaveNum to random(hiOctave - loOctave + 1) - 1
- return (12 * (octaveNum + loOctave)) + noteNum
- end
-
- on constrainHalfToneToScale instrument, halfTone
- set scale to getAt(gScales, getAt(gInstrumentScale, instrument))
- set numIntervals to count(scale)
- repeat with interval = 1 to numIntervals
- set theValue to getAt(scale, interval)
- if theValue >= halfTone then
- return theValue
- end if
- end repeat
- return getAt(scale, numIntervals)
- end
-
- on indexedNoteInInstrumentScale instrument, index
- set scale to getAt(gScales, getAt(gInstrumentScale, instrument))
- set maxIndex to count(scale)
- set octave to index / (maxIndex + 1)
- set index to ((index - 1) mod maxIndex) + 1
- return getAt(scale, index) + (12 * octave)
- end
-